﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Shared;//负责解释TableLogOnInfo类
using CrystalDecisions.CrystalReports.Engine;//负责解释ReportDocument类
using Microsoft.ApplicationBlocks.Data;
using System.Data.SqlClient;

public partial class CrystalReport_VerificationList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] != null)
        {
            DataSetCrystal dsc = new DataSetCrystal();
            int j = 1;
            string connString = ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString;
            string cmdtext = "";
            if (Session["UserStreet"].ToString() == "海曙")
            {
                lblstreet.Visible = true;
                ddlstreet.Visible = true;
                if (ddlstreet.SelectedValue == "海曙")
                    cmdtext = @"SELECT Apply.apply_address, Applicant.app_title, Applicant.app_name,Applicant.app_idcard,Apply.apply_street,Apply.apply_noid
                           ,Apply.apply_id FROM Applicant INNER JOIN Apply ON Applicant.app_noid = Apply.apply_noid WHERE Apply.apply_passed=2 AND Apply.apply_noid IN (SELECT adm_noid FROM Admissibility WHERE adm_checked=0)";
                else
                    cmdtext = @"SELECT Apply.apply_address, Applicant.app_title, Applicant.app_name,Applicant.app_idcard, Apply.apply_street,Apply.apply_noid
                           ,Apply.apply_id FROM Applicant INNER JOIN Apply ON Applicant.app_noid = Apply.apply_noid WHERE Apply.apply_street='" + ddlstreet.SelectedValue + "' AND Apply.apply_passed=2 AND Apply.apply_noid IN (SELECT adm_noid FROM Admissibility WHERE adm_checked=0)";
            }
            else
                cmdtext = @"SELECT Apply.apply_address, Applicant.app_title, Applicant.app_name,Applicant.app_idcard, Apply.apply_street,Apply.apply_noid
                           ,Apply.apply_id FROM Applicant INNER JOIN Apply ON Applicant.app_noid = Apply.apply_noid WHERE Apply.apply_street='" + Session["UserStreet"].ToString() + "' AND Apply.apply_passed=2 AND Apply.apply_noid IN (SELECT adm_noid FROM Admissibility WHERE adm_checked=0)";
            SqlDataReader dr = SqlHelper.ExecuteReader(connString, CommandType.Text, cmdtext);
            DataTable dt = dsc.Tables["VerificationList"];
            while (dr.Read())
            {
                DataRow datar = dt.NewRow();
                for (int i = 0; i < dr.FieldCount; i++)
                {
                    datar[i] = dr[i];
                }
                //datar[7] = j;
                j++;
                dt.Rows.Add(datar);
            }
            dr.Close();
            //使用报表对象加载报表
            ReportDocument myReport = new ReportDocument();
            string reportPath = Server.MapPath("~/CrystalReport/VerificationList.rpt");
            myReport.Load(reportPath);
            //绑定数据集，注意，一个报表用一个数据集。
            myReport.SetDataSource(dsc);
            CrystalReportViewer1.ReportSource = myReport;

            ParameterFields paramFields = new ParameterFields();
            ParameterField paramField = new ParameterField();
            ParameterDiscreteValue pdValue = new ParameterDiscreteValue();

            paramField.ParameterFieldName = "Street";
            if (Session["UserStreet"].ToString() == "海曙")
            {
                pdValue.Value = "(" + ddlstreet.SelectedValue + ")";
            }
            else
                pdValue.Value = "(" + Session["UserStreet"].ToString() + ")";
            paramField.CurrentValues.Add(pdValue);
            paramFields.Add(paramField);

            CrystalReportViewer1.ParameterFieldInfo = paramFields;
        }
        else
            Response.Redirect("~/Login.aspx");
    }
        
}
